<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<%
	String datetime = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()); //获取系统时间 
	request.setAttribute("currentTime", datetime);
%>
<html>
<script>
	var ctx = "${ctx}";
</script>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>位置广告编辑</title>

<meta name="keywords" content="bootstrap框架,响应式后台">
<meta name="description" content="完全响应式，基于Bootstrap3扁平化主题，使用了Html5+CSS3">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">

<!-- 基础样式 -->
<link href="${ctx}/static/css/bootstrap.min.css?v=${static_version}"
	rel="stylesheet">
<link
	href="${ctx}/static/css/font-awesome.min.css?v=4.4.0?v=${static_version}"
	rel="stylesheet">
<link href="${ctx}/static/css/animate.min.css?v=${static_version}"
	rel="stylesheet">
<link href="${ctx}/static/css/style.min.css?v=${static_version}"
	rel="stylesheet">
<link href="${ctx}/static/css/common.css?v=${static_version}"
	rel="stylesheet" />
<link href="//at.alicdn.com/t/font_9x03jhokyws9vn29.css"
	rel="stylesheet">
<!-- 插件样式 -->
<link
	href="${ctx}/static/css/plugins/webuploader/webuploader.css?v=${static_version}/"
	rel="stylesheet">
<link href="${ctx}/static/css/plugins/datapicker/datepicker3.css"
	rel="stylesheet">
<link href="${ctx}/static/plugins/region/css/city-picker.css"
	rel="stylesheet">
<link href="${ctx}/static/plugins/region/css/main.css?v=1"
	rel="stylesheet">

</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content  animated fadeInRight">
		<div class="ibox float-e-margins">

			<!-- 发布广告位  -->
			<div class="ibox-title">
				<h5>位置广告</h5>
			</div>

			<div class="ibox-content">
				<form class="form-group" id="table_form">
					<div class="form-horizontal">
						<div class="form-group">
							<input type="hidden" value="${u_advert.id}" id="advertid"
								name="id"> <label class="col-sm-2 control-label">
								广告位 </label>
							<div class="col-sm-3 m-l-n">
								<select id="position_id" name="position_id"
									<c:if test="${!empty u_advert}">disabled="disabled"</c:if>
									onchange="showPrice()" class="form-control">
									<option value="" data_price="">----选择广告位----</option>
									<c:forEach items="${u_advert_positions}" var="position">
										<c:choose>
											<c:when test="${!empty u_advert}">
												<option value="${position.id}"
													data_price="${position.unit_price}"
													<c:if test="${u_advert.position_id==position.id}">
														selected="selected"
														</c:if>>${position.position_name}
												</option>
											</c:when>
											<c:otherwise>
												<option value="${position.id}"
													data_price="${position.unit_price}"
													<c:if
													test="${positionid==position.id}">
														selected="selected"
														</c:if>>${position.position_name}
												</option>
											</c:otherwise>
										</c:choose>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">单价</label>
							<div class="col-sm-2 mt-5" id="positionprice">0</div>
							<div class="mt-5">（元/天）</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">投放时间 </label>
							<div class="col-sm-4 input-daterange input-group">
								<input type="text" class="form-control" name="start_time"
									id="start_time"
									<c:if test="${!empty u_advert}">disabled="disabled"</c:if>
									value="${empty u_advert.start_time?currentTime:fn:split(u_advert.start_time,' ')[0]}">
								<span class="input-group-addon"> 至 </span> <input type="text"
									class="form-control" name="end_time" id="end_time"
									<c:if test="${!empty u_advert}">disabled="disabled"</c:if>
									value="${empty u_advert.end_time?currentTime:fn:split(u_advert.end_time,' ')[0]}">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">投放时间天数 </label>
							<div class="col-sm-5 mt-5" id="daynum">1</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">总计</label>
							<div class="col-sm-2 m-l-n">
								<input type="text" class="form-control"
									value="${u_advert.total_amount}" id="total_amount"
									readonly="readonly" name="total_amount">
							</div>
							<div class="mt-5 ml-10">（元）</div>
						</div>
						<div class="form-group" style="display: none;">
							<label class="col-sm-2 control-label">类型 </label>
							<div class="col-sm-2 m-l-n">
								<select name="resource_type" class="form-control">
									<!-- 	<option value="">----选择类型----</option> -->
									<option value="0"
										<c:if test="${u_advert.resource_type==0}"> selected="selected"</c:if>>图片
									</option>
									<%-- <option value="1"
										<c:if test="${u_advert.resource_type==1}"> selected="selected"</c:if>>视频
									</option> --%>
								</select>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">缩略图</label>
							<div class="col-sm-10 m-l-n">

								<div class="col-sm-2 m-l-n">
									<a id="filePicker_covers"><i class="iconfont icon-plus1"></i></a>
									<br />尺寸：380px *380px<br />格式：PNG
								</div>

								<div id="fileList_covers" class="col-sm-2 uploader-list">
									<c:if test="${!empty u_advert.covers}">
										<div class="file-item">
											<c:choose>
												<c:when test="${u_advert.resource_type==0}">
													<img src="${u_advert.covers}" />
												</c:when>
												<c:otherwise>
													<img src="${u_advert.covers}?vframe/png/offset/3/" />
												</c:otherwise>
											</c:choose>
										</div>
									</c:if>
								</div>

								<input type="hidden" class="input-text"
									value="${u_advert.covers}" placeholder="" id="covers"
									name="covers" datatype="*" nullmsg="不能为空">
							</div>
						</div>

						<div class="form-group">
							<label class="col-sm-2 control-label">选择内页H5模板 </label>
							<div class="col-sm-8 m-l-n">
								<div class="lightBoxGallery">
									<c:forEach items="${templates}" var="template">
										<a
											onclick="selectTemplate('${template.tpl_level}',${template.template_id})"><div
												class="tmplate-item">
												<img src="${template.tpl_thumb}" style="height: 150px;">
												<div class="tmplate-name" style="text-align: center;">${template.tpl_name}&nbsp;&nbsp;${template.tpl_levelstr}</div>
											</div> </a>
									</c:forEach>
								</div>
							</div>
						</div>

						<div class="form-group">
							<label class="col-sm-2 control-label"> 排序 </label>
							<div class="col-sm-2 m-l-n">
								<input type="text" class="form-control" name="sort"
									value="${u_advert.sort}">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2"></label>
							<div class="col-sm-10 m-l-n">
								<button class="btn btn-primary radius col-sm-2" type="button"
									onclick="save()">保存并提交</button>
								&nbsp;&nbsp;&nbsp;&nbsp;
								<button class="btn btn-white radius pl-30 pr-30" type="button">取消</button>
							</div>
						</div>

						<input type="hidden" name="template_id" id="template_id"
							value="${u_advert.template_id}" />

					</div>
				</form>
			</div>
		</div>
	</div>
</body>
<!-- 基础脚本 -->
<script src="${ctx}/static/js/jquery.min.js?v=${static_version}">
	</script>
<script src="${ctx}/static/js/bootstrap.min.js?v=${static_version}">
	</script>
<!-- 插件脚本 -->
<script
	src="${ctx}/static/js/plugins/validate/jquery.validate.min.js?v=${static_version}">
	</script>
<script
	src="${ctx}/static/js/plugins/layer/layer.js?v=${static_version}"></script>
<script
	src="${ctx}/static/js/plugins/datapicker/bootstrap-datepicker.js"></script>
<script
	src="${ctx}/static/js/plugins/webuploader/webuploader.min.js?v=${static_version}"></script>
<!-- 支付ping++ -->
<script src="${ctx}/static/js/pingpp.js"></script>
<!-- 本页面脚本 -->
<script src="${ctx}/static/js/uthinkjs/positionadvert.js?v=1.1"></script>
<script>
	function save(){
		$.ajax({
			type:"post",
			url:"${ctx}/create_advert_positionadvert",
			data:$("#table_form").serialize(),
			success:function(msg){
				var info = eval('('+msg+')');
				if(info.error == "0000"){
					if($("#advertid").val()==""||$("#advertid").val()==null){//添加
						window.location.href="${ctx}/advert_pay?rid="+info.datas+"&return_url=${ctx}/advert_positionadvert-list";
					}else{						
						layer.msg('修改成功', {icon:5,time:1000});						
						var index = parent.layer.getFrameIndex(window.name);
						parent.$('.btn-refresh').click();
						parent.layer.close(index);	
					}
				}else{
					layer.msg('创建失败', {icon:5,time:1000});
				}	
			}
		})
	}
</script>
</html>